export default {
	components: {},
	data() {
		return {
			dynamicList: [],
			list: [],
			mobile: this.$serviceMobile,
			userInfo: {},
			versionstr: '',
			fileSizeString: '0B',
			version_number: '',
			group_name: '',
			buttons: {
				btn3: [{
						title: '网点',
						imageUrl: '/static/mine/wangdian.png',
						tag: 'dian'
					},
					{
						title: '员工',
						imageUrl: '/static/mine/yuangong.png',
						tag: 'yuan'
					},
					// #ifdef APP
					 {
					 	title: '打印机',
					 	imageUrl: '/static/mine/yuangong.png',
					 	tag: 'print'
					 },
					// #endif
					{
						title: '清除缓存',
						imageUrl: '/static/mine/mine_clear.png',
						tag: 'qlhc'
					},
					{
						title: '版本信息',
						imageUrl: '/static/mine/mine_version.png',
						tag: 'bbxx'
					}, {
						title: '联系客服',
						imageUrl: '/static/mine/mine_kefu.png',
						tag: 'lxkf'
					}
				],
			},
		};
	},
	onLoad() {
		if (!this.check.isLogin()) {
			uni.navigateTo({
				url: "/pages/login/login/login"
			});
		}

	},
	onShow() {
		if (this.check.isLogin()) {
			this.mineShipperInfoData();
		}
	},
	methods: {
		getLevelTitle() {
			if (this.userInfo.site_level == 1) {
				return "三方网点"
			} else if (this.userInfo.site_level == 2) {
				return "三方二级网点"
			} else {
				return this.userInfo.site_name;
			}
		},
		listBtnClick(e) {
			switch (e.tag) {
				case 'qlhc': { //清除缓存
					const that = this
					uni.showModal({
						title: '提示',
						content: '是否清除缓存',
						confirmText: '确定',
						success: res => {
							if (res.confirm) {
								that.clearCache();
							}
						}
					});
					break;
				}
				case 'lxkf': { //联系客服
					this.lianxi();
					break;
				}
				case 'bbxx': { //版本信息
					const accountInfo = uni.getAppBaseInfo();
					this.versionstr = accountInfo.appVersion;
					const that = this
					uni.showModal({
						title: '提示',
						content: this.versionstr + '',
						confirmText: '确定',
						success: res => {
							if (res.confirm) {
								that.$util.redirectToHome(true);
							} else {

							}
						}
					});
					break;
				}
				case 'dian': { //网点
					uni.navigateTo({
						url: "/pages/mine/site/my-site-list"
					});
					break;
				}
				case 'yuan': { //员工
					uni.navigateTo({
						url: "/pages/mine/staff/my-staff-list"
					});
					break;
				}
				case 'print': { //打印机
					uni.navigateTo({
						url: "/pages/mine/print/setting/pringSetting"
					});
					break;
				}
				default: {

				}
			}
		},
		getUserAvatar() {
			return '/static/mine/wxlogo.png'
			if (this.check.isNull(this.userInfo.avatar) && this.check.isNull(getApp().globalData.userInfo.avatar)) {
				return '/static/mine/wxlogo.png'
			} else {
				return this.check.isNull(this.userInfo.avatar) == false ? this.userInfo.avatar : getApp().globalData
					.userInfo.avatar;
			}
		},
		headClick() {
			// this.$util.redirectTo('/pages/mine/myInfo/myInfo');
		},
		lianxi() {
			uni.makePhoneCall({
				phoneNumber: this.$serviceMobile,
				success: () => {
					console.log('成功拨打电话');
				}
			});
		},
		logout() {
			const that = this
			uni.showModal({
				title: '提示',
				content: '是否退出',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
						that.$util.redirectToHome(true);
					} else {

					}
				}
			});
		},
		formatSize() {
			// #ifdef APP-PLUS
			let that = this;
			plus.cache.calculate(function(size) {
				let sizeCache = parseInt(size);
				if (sizeCache == 0) {
					that.fileSizeString = '0B';
				} else if (sizeCache < 1024) {
					that.fileSizeString = sizeCache + 'B';
				} else if (sizeCache < 1048576) {
					that.fileSizeString = (sizeCache / 1024).toFixed(2) + 'KB';
				} else if (sizeCache < 1073741824) {
					that.fileSizeString = (sizeCache / 1048576).toFixed(2) + 'MB';
				} else {
					that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + 'GB';
				}
			});
			// #endif

		},
		/**
		 * 商家个人信息
		 */
		mineShipperInfoData() {
			var userinfo = uni.getStorageSync(this.preutils.userinfo)
			var data = {
				mid: userinfo.id
			};
			this.http.sendRequest({
				api: this.api.login.memberInfo,
				data: data,
				success: res => {
					if (res.code == 1 && res.data) {
						this.userInfo = res.data;
						if (this.userInfo.group_list.length > 0) {
							this.group_name = this.userInfo.group_list[0].name;
						}
						console.log(res)
						getApp().globalData.userInfo = this.userInfo;
					}
				}
			});
		},
		clearCache() {
			let that = this;
			let os = plus.os.name;
			if (os == 'Android') {
				let main = plus.android.runtimeMainActivity();
				let sdRoot = main.getCacheDir();
				let files = plus.android.invoke(sdRoot, 'listFiles');
				let len = files.length;
				for (let i = 0; i < len; i++) {
					let filePath = '' + files[i]; // 没有找到合适的方法获取路径，这样写可以转成文件路径
					plus.io.resolveLocalFileSystemURL(
						filePath,
						function(entry) {
							if (entry.isDirectory) {
								entry.removeRecursively(
									function(entry) {
										//递归删除其下的所有文件及子目录
										uni.showToast({
											title: '缓存清理完成',
											duration: 2000
										});
										that.formatSize(); // 重新计算缓存
									},
									function(e) {
										console.log(e.message);
									}
								);
							} else {
								entry.remove();
							}
						},
						function(e) {
							console.log('文件路径读取失败');
						}
					);
				}
			} else {
				// ios暂时未找到清理缓存的方法，以下是官方提供的方法，但是无效，会报错
				plus.cache.clear(function() {
					uni.showToast({
						title: '缓存清理完成',
						duration: 2000
					});
					that.formatSize();
				});
			}
		},
	}
};